package org.coco24.pmstudio.window

import com.badlogic.gdx.scenes.scene2d.Stage
import com.kotcrab.vis.ui.building.CenteredTableBuilder
import com.kotcrab.vis.ui.building.OneColumnTableBuilder
import com.kotcrab.vis.ui.building.StandardTableBuilder
import com.kotcrab.vis.ui.building.utilities.Alignment
import com.kotcrab.vis.ui.building.utilities.CellWidget
import com.kotcrab.vis.ui.building.utilities.Padding
import com.kotcrab.vis.ui.widget.VisLabel
import com.kotcrab.vis.ui.widget.VisTextButton
import com.kotcrab.vis.ui.widget.VisTextField
import com.kotcrab.vis.ui.widget.VisWindow
import org.coco24.pmstudio.`interface`.SimpleWindowCallback
import org.coco24.pmstudio.util.UIUtils.centeredWidget
import org.coco24.pmstudio.util.UIUtils.setOnChanged

class NewWindow(title: String, callabck: SimpleWindowCallback, initialText: String = ""): VisWindow(title)
{
    val textField = VisTextField(initialText)
    val cancelButton = VisTextButton("取消")
    val confirmButton = VisTextButton("确定")
    init
    {
        val tableBuilder = StandardTableBuilder()
        addCloseButton()
        tableBuilder.append(VisLabel("名称："), textField).row()

        tableBuilder.append(centeredWidget(cancelButton), centeredWidget(confirmButton))
        add(tableBuilder.build())
        pack()

        setOnChanged(cancelButton, Runnable { callabck.onCanceled();close() })
        setOnChanged(confirmButton, Runnable { callabck.onConfirmed(textField.text);close() })
    }
    fun show(stage: Stage)
    {
        stage.addActor(this)
        centerWindow()
        fadeIn()
    }
}